#!/bin/bash

. ./functions.sh
cpanconfigfile=$LOCALPERL/lib/5.8.8/CPAN/Config.pm

echo "Going to configure the file
  $cpanconfigfile
  for cpan now.
  This may require input from you.
  But not very much -- just one key press.
  If you are asked \"ready for manual config?\"
  just answer no. 
  Got that?
  Press \"enter\" to continue"
read input
echo "ok....."
echo "perl is `which perl`"
echo "cpan is `which cpan`"
perl -MCPAN -e 'CPAN::Shell->o("conf", "defaults")';

echo "Going to update CPAN to latest version"
perl -MCPAN -MCPAN::Config -e 'install CPAN'
#[[ -d ~/.cpan ]] && exit_wrapper "~/.cpan exists, that's bad"

#echo "changing $HOME/.cpan to $EXTERNAL_DEPENDENCIES/.cpan in $cpanconfigfile"
#perl -pi.bak -e 's/$ENV{HOME}/$ENV{EXTERNAL_DEPENDENCIES}/g' $cpanconfigfile

echo "CPAN has been updated to the latest version
  We need to configure Config.pm again,
  because the newer version has additional configuration paramaters.
  This may require some input from you.
  But not much -- just a few presses of the \"enter\" key,
  to accept all the defaults proposed.
  Got that?
  Press \"enter\" to continue"
read input
perl -MCPAN -MCPAN::Config -e 'CPAN::Shell->o("conf", "init") ; CPAN::Shell->o("conf", "commit")';    

#[[ -d ~/.cpan ]] && exit_wrapper "~/.cpan exists, that's bad"
#perl -MCPAN -e 'install CPAN'

